PVector speed;
PVector ellipsePos;
PVector startPos;
PVector endPos;
static float epsilon = 0.0001;
void setup()
{
  size(300, 300);
  smooth();
  noStroke();
  fill(125);
  startPos = new PVector(30, 40);
  endPos = new PVector(240, 280);
  ellipsePos = new PVector(startPos.x, startPos.y);
  speed = new PVector(endPos.x - startPos.x, endPos.y - startPos.y);
  speed.normalize();
  println("speed.x " + speed.x + " speed.y " + speed.y);
}

boolean isOnline()
{
  float dis1 = startPos.dist(ellipsePos);
  float dis2 = ellipsePos.dist(endPos);
  float disa = startPos.dist(endPos);
  println("dis1 " + dis1 + " dis2 " + dis2 + " disa " + disa);
  if (abs(dis1 + dis2 - disa) < epsilon) return true;
  else return false;
}

void draw()
{
  background(255);
  println("speed.x " + speed.x + " speed.y " + speed.y);
  if (isOnline()) {
    ellipse(ellipsePos.x, ellipsePos.y, 3, 3);
    ellipsePos.add(speed);
  } else {
    speed.mult(-1.0);
    ellipsePos.add(speed);
  }
}
